package com.codeanalysissys.backend.python;
import java.util.Arrays;
import java.util.Objects;
/**
 * A simple structure for storing key information about a Python class method.
 *
 * @author WenLiang Peng
 */
public class PythonMethod {
    public final String NAME;
    public final String[] ARGUMENTS;
    public final boolean IS_ASYNC;
    public final String RETURN_TYPE;
    public final int LINE_OF_CODE;

    public PythonMethod(String name, String[] arguments, String returnType, int lineOfCode, boolean isAsync) {
        NAME = name;
        ARGUMENTS = arguments;
        IS_ASYNC = isAsync;
        RETURN_TYPE = returnType;
        LINE_OF_CODE = lineOfCode;
    }

    @Override
    public String toString() {
        String modifiers = "";
        if (IS_ASYNC) {
            modifiers += "async ";
        }
        String args = Arrays.toString(ARGUMENTS);
        return modifiers + String.format("def %s(%s) -> %s { LINE: %d }", NAME, args, RETURN_TYPE, LINE_OF_CODE);
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof PythonMethod))
            return false;
        PythonMethod other = (PythonMethod) obj;
        return NAME.equals(other.NAME) && Arrays.equals(ARGUMENTS, other.ARGUMENTS) && RETURN_TYPE.equals(other.RETURN_TYPE)
                && LINE_OF_CODE == other.LINE_OF_CODE && IS_ASYNC == other.IS_ASYNC;
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(NAME, IS_ASYNC, RETURN_TYPE, LINE_OF_CODE);
        result = 31 * result + Arrays.hashCode(ARGUMENTS);
        return result;
    }
}
